package com.train.${module}.facade;

import cn.hutool.core.bean.BeanUtil;
import com.train.${module}.req.${Domain}AddOrEditReq;
import com.train.${module}.req.${Domain}PageReq;
import com.train.${module}.resp.${Domain}PageResp;
import com.train.common.resp.CommonResp;
import com.train.common.resp.PageResp;
import com.train.${module}.dto.${Domain}AddOrEditDTO;
import com.train.${module}.dto.${Domain}PageDTO;
import com.train.${module}.service.${Domain}Service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

/**
 * ${domain} Facade 实现类
 * @author ${author}
 * @createDate ${date}
 */
@RestController
@Slf4j
@RequiredArgsConstructor
public class ${Domain}FacadeImpl implements ${Domain}Facade {

    private final ${Domain}Service ${domain}Service;

    @Override
    public CommonResp pageList(${Domain}PageReq req) {
        ${Domain}PageDTO ${domain}PageDTO = BeanUtil.copyProperties(req, ${Domain}PageDTO.class);
        PageResp<${Domain}PageResp> pageResp = ${domain}Service.pageList(${domain}PageDTO);
        return CommonResp.ok(pageResp);
    }

    @Override
    public CommonResp add(${Domain}AddOrEditReq req) {
        ${Domain}AddOrEditDTO ${domain}AddOrEditDTO = BeanUtil.copyProperties(req, ${Domain}AddOrEditDTO.class);
        ${domain}Service.addOrEdit${Domain}(${domain}AddOrEditDTO);
        return CommonResp.ok();
    }

    @Override
    public CommonResp edit(${Domain}AddOrEditReq req) {
        ${Domain}AddOrEditDTO ${domain}AddOrEditDTO = BeanUtil.copyProperties(req, ${Domain}AddOrEditDTO.class);
        ${domain}Service.addOrEdit${Domain}(${domain}AddOrEditDTO);
        return CommonResp.ok();
    }

    /**
     * 删除接口
     */
    public CommonResp delete(Long id) {
        ${domain}Service.remove(id);
        return CommonResp.ok();
    }
}
